<template>
	<div class="flow-nodes">
		<branch-wrap
			:nodeConfig.sync="nodeConfig.childNode"
			:flowPermission.sync="flowPermission"
			:isTried.sync="isTried"
			v-if="nodeConfig.type == 4"
		/>
		<node-wrap
			:nodeConfig.sync="nodeConfig.childNode"
			:flowPermission.sync="flowPermission"
			:isTried.sync="isTried"
			v-else
		/>
		<flow-nodes
			v-if="!!nodeConfig.childNode"
			:nodeConfig.sync="nodeConfig.childNode"
			:flowPermission.sync="flowPermission"
			:isTried.sync="isTried"
		/>
	</div>
</template>
<script>
import NodeWrap from "./node-wrap";
import BranchWrap from "./branch-wrap";

export default {
	name: "flow-nodes",
	components: {
		NodeWrap,
		BranchWrap
	},
	props: {
		nodeConfig: {
			type: Object,
			default: () => ({})
		},
		flowPermission: {
			type: Array,
			default: () => []
		},
		isTried: {
			type: Boolean,
			default: false
		}
	},
	created() {
		// console.log(this.nodeConfig);
	},
	methods: {}
};
</script>
<style lang="scss" scoped>
::v-deep {
	.error_tip {
		position: absolute;
		top: 0px;
		right: 0px;
		transform: translate(150%, 0px);
		font-size: 24px;
	}
	.top-left-cover-line {
		left: -1px;
	}

	.top-left-cover-line,
	.top-right-cover-line {
		position: absolute;
		height: 4px;
		width: 50%;
		background-color: #f5f5f7;
		top: -3px;
	}

	.top-right-cover-line {
		right: -1px;
	}

	.bottom-left-cover-line {
		left: -1px;
	}

	.bottom-left-cover-line,
	.bottom-right-cover-line {
		position: absolute;
		height: 4px;
		width: 50%;
		background-color: #f5f5f7;
		bottom: -3px;
	}

	.bottom-right-cover-line {
		right: -1px;
	}
	.editable-title-input {
		flex: none;
		height: 18px;
		padding-left: 4px;
		text-indent: 0;
		font-size: 12px;
		line-height: 18px;
		z-index: 1;
		color: #333;
		border: 1px solid $primary;
		border-radius: 3px;
	}

	.editable-title-input:hover {
		text-decoration: none;
	}

	.auto-judge:hover .editable-title,
	.node-wrap-box:hover .editable-title {
		border-bottom: 1px dashed #fff;
	}
	.auto-judge:hover .editable-title.editing,
	.node-wrap-box:hover .editable-title.editing {
		text-decoration: none;
		border: 1px solid #d9d9d9;
	}
	.editable-title {
		line-height: 15px;
		overflow: hidden;
		white-space: nowrap;
		text-overflow: ellipsis;
		border-bottom: 1px dashed transparent;
		&:before {
			content: "";
			position: absolute;
			top: 0;
			left: 0;
			bottom: 0;
			right: 40px;
		}
		&:hover {
			border-bottom: 1px dashed #fff;
		}
	}
	.auto-judge {
		position: relative;
		width: 220px;
		min-height: 72px;
		background: #fff;
		border-radius: 4px;
		padding: 14px 19px;
		cursor: pointer;
		&:after {
			pointer-events: none;
			content: "";
			position: absolute;
			top: 0;
			bottom: 0;
			left: 0;
			right: 0;
			z-index: 2;
			border-radius: 4px;
			border: 1px solid transparent;
			transition: all 0.1s cubic-bezier(0.645, 0.045, 0.355, 1);
			box-shadow: 0 2px 5px 0 rgba(0, 0, 0, 0.1);
		}
		&.active,
		&:active,
		&:hover {
			&:after {
				border: 1px solid $primary;
				box-shadow: 0 0 6px 0 mix(#fff, $primary, 30%);
			}
			.close {
				display: block;
			}
		}
		&.error:after {
			border: 1px solid #f25643;
			box-shadow: 0 2px 5px 0 rgba(0, 0, 0, 0.1);
		}
		.title-wrapper {
			position: relative;
			font-size: 12px;
			color: #15bc83;
			text-align: left;
			line-height: 16px;
			.editable-title {
				display: inline-block;
				max-width: 120px;
				overflow: hidden;
				white-space: nowrap;
				text-overflow: ellipsis;
			}
			.priority-title {
				display: inline-block;
				float: right;
				margin-right: 10px;
				color: rgba(25, 31, 37, 0.56);
			}
		}
		.placeholder {
			color: #bfbfbf;
		}
		.close {
			display: none;
			position: absolute;
			right: -10px;
			top: -10px;
			width: 20px;
			height: 20px;
			font-size: 14px;
			color: rgba(0, 0, 0, 0.7);
			border-radius: 50%;
			text-align: center;
			line-height: 20px;
			z-index: 2;
		}
		.content {
			font-size: 14px;
			color: #191f25;
			text-align: left;
			margin-top: 6px;
			overflow: hidden;
			text-overflow: ellipsis;
			display: -webkit-box;
			-webkit-line-clamp: 3;
			-webkit-box-orient: vertical;
		}
		.sort-left,
		.sort-right {
			position: absolute;
			top: 0;
			bottom: 0;
			display: none;
			z-index: 1;
			font-size: 12px;
			color: #000;
		}
		.sort-left {
			left: 0;
			border-right: 1px solid #f6f6f6;
		}
		.sort-right {
			right: 0;
			border-left: 1px solid #f6f6f6;
		}
		&:hover {
			.sort-left,
			.sort-right {
				display: flex;
				align-items: center;
				&:hover {
					background: #efefef;
				}
			}
		}
	}

	.branch-wrap,
	.node-wrap {
		display: inline-flex;
		width: 100%;
	}

	.node-wrap {
		flex-direction: column;
		justify-content: flex-start;
		align-items: center;
		flex-wrap: wrap;
		padding: 0 50px;
		position: relative;
	}
	.auto-judge:hover .editable-title {
		border-color: #15bc83;
	}
	.node-wrap-box {
		display: inline-flex;
		flex-direction: column;
		position: relative;
		width: 220px;
		min-height: 72px;
		flex-shrink: 0;
		background: #fff;
		border-radius: 4px;
		cursor: pointer;
		&:after {
			pointer-events: none;
			content: "";
			position: absolute;
			top: 0;
			bottom: 0;
			left: 0;
			right: 0;
			z-index: 2;
			border-radius: 4px;
			border: 1px solid transparent;
			transition: all 0.1s cubic-bezier(0.645, 0.045, 0.355, 1);
			box-shadow: 0 2px 5px 0 rgba(0, 0, 0, 0.1);
		}
		&.active,
		&:active,
		&:hover {
			&:after {
				border: 1px solid $primary;
				box-shadow: 0 0 6px 0 mix(#fff, $primary, 30%);
			}
			.close {
				display: block;
			}
		}
		&.error:after {
			border: 1px solid #f25643;
			box-shadow: 0 2px 5px 0 rgba(0, 0, 0, 0.1);
		}
		.title {
			position: relative;
			display: flex;
			align-items: center;
			padding-left: 16px;
			padding-right: 30px;
			width: 100%;
			height: 24px;
			line-height: 24px;
			font-size: 12px;
			color: #fff;
			text-align: left;
			background: #576a95;
			border-radius: 4px 4px 0 0;
			.icon {
				font-size: 12px;
				margin-right: 5px;
			}
		}
		.placeholder {
			color: #bfbfbf;
		}
		.close {
			display: none;
			position: absolute;
			right: 10px;
			top: 50%;
			transform: translateY(-50%);
			width: 20px;
			height: 20px;
			font-size: 14px;
			color: #fff;
			border-radius: 50%;
			text-align: center;
			line-height: 20px;
		}
		.content {
			position: relative;
			font-size: 14px;
			padding: 16px;
			padding-right: 30px;
			.text {
				overflow: hidden;
				text-overflow: ellipsis;
				display: -webkit-box;
				-webkit-line-clamp: 3;
				-webkit-box-orient: vertical;
			}
			.arrow {
				position: absolute;
				right: 10px;
				top: 50%;
				transform: translateY(-50%);
				width: 20px;
				height: 14px;
				font-size: 14px;
				color: #979797;
			}
		}
		&.start-node .content .text {
			display: block;
			white-space: nowrap;
		}
		&:before {
			content: "";
			position: absolute;
			top: -12px;
			left: 50%;
			transform: translateX(-50%);
			width: 0;
			height: 4px;
			border-style: solid;
			border-width: 8px 6px 4px;
			border-color: #cacaca transparent transparent;
			background: #f5f5f7;
		}
		&.start-node:before {
			content: none;
		}
	}

	.branch-box-wrap {
		display: flex;
		flex-direction: column;
		flex-wrap: wrap;
		align-items: center;
		min-height: 270px;
		width: 100%;
		flex-shrink: 0;
	}
	.branch-box {
		display: flex;
		overflow: visible;
		min-height: 180px;
		height: auto;
		border-bottom: 2px solid #ccc;
		border-top: 2px solid #ccc;
		position: relative;
		margin-top: 15px;
		.col-box {
			background: #f5f5f7;
			&:before {
				content: "";
				position: absolute;
				top: 0;
				left: 0;
				right: 0;
				bottom: 0;
				z-index: 0;
				margin: auto;
				width: 2px;
				height: 100%;
				background-color: #cacaca;
			}
			.condition-node {
				min-height: 220px;
			}
			.condition-node,
			.condition-node-box {
				display: inline-flex;
				flex-direction: column;
			}
			.condition-node-box {
				padding-top: 30px;
				padding-right: 50px;
				padding-left: 50px;
				justify-content: center;
				align-items: center;
				flex-grow: 1;
				position: relative;
				&:before {
					content: "";
					position: absolute;
					top: 0;
					left: 0;
					right: 0;
					bottom: 0;
					margin: auto;
					width: 2px;
					height: 100%;
					background-color: #cacaca;
				}
			}
		}
	}
	.add-branch {
		border: none;
		outline: none;
		user-select: none;
		justify-content: center;
		font-size: 12px;
		padding: 0 10px;
		height: 30px;
		line-height: 30px;
		border-radius: 15px;
		color: $primary;
		background: #fff;
		box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.1);
		position: absolute;
		top: -16px;
		left: 50%;
		transform: translateX(-50%);
		transform-origin: center center;
		cursor: pointer;
		z-index: 1;
		display: inline-flex;
		align-items: center;
		transition: all 0.3s cubic-bezier(0.645, 0.045, 0.355, 1);
		&:hover {
			transform: translateX(-50%) scale(1.1);
			box-shadow: 0 8px 16px 0 rgba(0, 0, 0, 0.1);
		}
		:active {
			transform: translateX(-50%);
			box-shadow: none;
		}
	}
	.col-box {
		display: inline-flex;
		flex-direction: column;
		align-items: center;
		position: relative;
	}
}
</style>
